package com.github.itdachen.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.itdachen.convert.DevTableColumnConvert;
import com.github.itdachen.entity.DevTableColumn;
import com.github.itdachen.mapper.IDevTableColumnMapper;
import com.github.itdachen.service.IDevTableColumnService;
import com.github.itdachen.sdk.dto.DevTableColumnDTO;
import com.github.itdachen.sdk.query.DevTableColumnQuery;
import com.github.itdachen.sdk.vo.DevTableColumnVO;
import com.github.itdachen.framework.core.response.TableData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 代码生成业务表字段 serverImpl
 *
 * @author 王大宸
 * @date 2023-09-23 21:25:55
 */
@Service
public class DevTableColumnServiceImpl implements IDevTableColumnService {
    private static final Logger logger = LoggerFactory.getLogger(DevTableColumnServiceImpl.class);

    private final IDevTableColumnMapper devTableColumnMapper;

    public DevTableColumnServiceImpl(IDevTableColumnMapper devTableColumnMapper) {
        this.devTableColumnMapper = devTableColumnMapper;
    }

    /***
     * 分页
     *
     * @author 王大宸
     * @date 2023-09-23 21:25:55
     * @param params 查询参数
     * @return com.github.itdachen.framework.core.response.TableData<com.github.itdachen.sdk.vo.DevTableColumnVo>
     */
    @Override
    public TableData< DevTableColumnVO > findDevTableColumnPage(DevTableColumnQuery params) throws Exception {
        Page< DevTableColumnVO > page = PageHelper.startPage(params.getPage(), params.getLimit());
        List< DevTableColumnVO > list = devTableColumnMapper.findDevTableColumnPage(params);
        return new TableData< DevTableColumnVO >(page.getTotal(), list);
    }

    /***
     * 新增
     *
     * @author 王大宸
     * @date 2023-09-23 21:25:55
     * @param devTableColumnDTO 新增数据
     * @return com.github.itdachen.sdk.vo.devTableColumnVO
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public DevTableColumnVO saveDevTableColumn(DevTableColumnDTO devTableColumnDTO) throws Exception {
        DevTableColumn devTableColumn = DevTableColumnConvert.toJavaObject(devTableColumnDTO);
       // EntityUtils.setCreatAndUpdateInfo(devTableColumn);
        devTableColumnMapper.saveDevTableColumn(devTableColumn);
        return DevTableColumnConvert.toJavaObjectVO(devTableColumn);
    }

    /***
     * 根据id查询
     *
     * @author 王大宸
     * @date 2023-09-23 21:25:55
     * @param id 需要查询数据的id
     * @return com.github.itdachen.sdk.vo.DevTableColumnVO
     */
    @Override
    public DevTableColumnVO getDevTableColumnById(String id) throws Exception {
        return devTableColumnMapper.getById(id);
    }

    /***
     * 修改
     *
     * @author 王大宸
     * @date 2023-09-23 21:25:55
     * @param devTableColumnDTO 更新数据
     * @return com.github.itdachen.sdk.vo.devTableColumnVO
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public DevTableColumnVO updateDevTableColumn(DevTableColumnDTO devTableColumnDTO) throws Exception {
        DevTableColumn devTableColumn = DevTableColumnConvert.toJavaObject(devTableColumnDTO);
        // EntityUtils.setUpdatedInfo(devTableColumn);
        devTableColumnMapper.updateDevTableColumn(devTableColumn);
        return DevTableColumnConvert.toJavaObjectVO(devTableColumn);
    }

    /***
     * 删除
     *
     * @author 王大宸
     * @date 2023-09-23 21:25:55
     * @param id 需要删除数据的id
     * @return int 影响行数
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int removeDevTableColumn(String id) throws Exception {
           return devTableColumnMapper.deleteDevTableColumnById(id);
    }

}
